package com.takeshequ;

import android.app.Application;
import android.os.Vibrator;
import android.support.v4.view.ViewPager;
import cn.jpush.android.api.JPushInterface;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.BDNotifyListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.loopj.android.http.AsyncHttpClient;

public class SMApplication extends Application {
	public LocationClient mLocationClient = null;
	public MyLocationListenner myListener = new MyLocationListenner();
	public NotifyLister mNotifyer = null;
	public Vibrator mVibrator01;

	public ViewPager viewPager;
	public AsyncHttpClient client = new AsyncHttpClient();

	@Override
	public void onCreate() {
		super.onCreate();
		mLocationClient = new LocationClient(this);
		mLocationClient.registerLocationListener(myListener);
		JPushInterface.setDebugMode(true);
		JPushInterface.init(this);
		setLocationOption();
	}

	public class MyLocationListenner implements BDLocationListener {
		@Override
		public void onReceiveLocation(BDLocation location) {
			if (location == null)
				return;
			Constants.address = location.getAddrStr();
			Constants.latitude = String.valueOf(location.getLatitude());
			Constants.longitude = String.valueOf(location.getLongitude());
		}

		public void onReceivePoi(BDLocation poiLocation) {
			if (poiLocation == null) {
				return;
			}
			Constants.address = poiLocation.getAddrStr();
			Constants.latitude = String.valueOf(poiLocation.getLatitude());
			Constants.longitude = String.valueOf(poiLocation.getLongitude());
		}
	}

	public class NotifyLister extends BDNotifyListener {
		public void onNotify(BDLocation mlocation, float distance) {
			mVibrator01.vibrate(1000);
		}
	}

	private void setLocationOption() {
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true); //
		option.setServiceName("com.baidu.location.service_v2.9");
		option.setPoiExtraInfo(false);
		option.setCoorType("bd09ll");
		option.setPriority(LocationClientOption.NetWorkFirst);
		option.setPoiNumber(10);
		option.disableCache(true);
		option.setScanSpan(5000);
		option.setAddrType("all");// 返回的定位结果包含地址信息
		mLocationClient.setLocOption(option);
		mLocationClient.start();

	}
}
